 $().ready(function() {

	/* var addNewSpan = '<span id="errormsg_container"></span>';
        $("#announcements-node-form").before(addNewSpan);*/
	
  $("#actform-node-form").validate({
										/* onfocusout: false,
  										 onkeyup: false,
  										 onclick: false,*/
										 //debug:true,
										 
					rules: {
						'field_act_dpt[und]': { 
							required: true,
							maxlength: 255,
							chkbadchar:true,
							valuenotequals: '_none',
						},
						
						'field_act_concerned_district[und][]':{
							//required: true,
							//maxlength: 255,
							//chkbadchar:true,
							multi_dist_select: true,
							
							},
							
						'field_act_title[und][0][value]': { 
						   required: true,
					       maxlength: 255,
						   chkbadchar:true,
						   valuenotequals: '_none',
						splchar:true,
						},
						'field_act_number[und][0][value]': { 
						   
					       //required : true,
						   maxlength: 255,
						   chkbadchar:true,
						   valuenotequals: '_none',
							splchar:true,
						},
						
						'field_act_year[und][0][value]': { 
                             digits : true,
                             minlength: 4,
                             maxlength: 4,
                             min:1640,
                            year_not_greater : true,
							

                        },
						
						'field_act_extent[und][0][value]': { 
						   //required: true,
					       maxlength: 255,
						   chkbadchar:true,
						   valuenotequals: '_none',
						splchar:true,
						},
						
						'field_act_comm_date[und][0][value][date]': { 
                           required: true,
                           chkbadchar:true,
                           dateformat:true,
                           date_notgreater_tdy:true,
                       },
						
						'field_act_objectives[und][0][value]': { 
						   required: true,
					       maxlength: 255,
						   chkbadchar:true,
						   valuenotequals: '_none',
						splchar:true,
						},
						
						'title': { 
							required: true,
							minlength: 5,
							maxlength: 255,
							chkbadchar:true,
							splchar:true,
						},
						
			
						'field_act_details[und]': { 
							required: true,
							maxlength: 200,
							chkbadchar:true,
							
						},
						
						 'field_act_url[und][0][value]':{
                             required: "#edit-field-act-details-und-onlineavailable:checked",
                             url: true,
chkbadchar:true,

                                               },
                         'files[field_act_file_upload_und_0]':{
                            required: "#edit-field-act-details-und-download:checked",
                            chkfile_format_size: true,
                                               },
						'field_act_keyword[und][0][value]':{
							minlength: 5,
							maxlength: 255,
							chkbadchar:true,
							splchar:true,							
						},
						
						
						
					
					},
                    messages: {
						'field_act_dpt[und]':{
							required: 'Please Select Concerned Department',
							maxlength:  'Maximum 255 character only allowed',
							chkbadchar: 'insert, select, update, delete, drop, alter, change, modify not allowed.',
							valuenotequals: 'Please Select Concerned Department',
							},
							
							'field_act_concerned_district[und][]':{
							required: 'Please Select Districts',
							maxlength:  'Maximum 255 character only allowed',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',	
							multi_dist_select: 'Please Select either All or Particular Districts',
							},
							
							'field_act_title[und][0][value]':{
							required: 'Please Enter Act title',
							maxlength:  'Maximum 255 character only allowed',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',	
							splchar:'Special Characters are not allowed',
							},
							
						   'field_act_number[und][0][value]':{
							required: 'Please Enter Act Number',
							maxlength:  'Maximum 255 character only allowed',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',	
							splchar:'Special Characters are not allowed',
							},
							
						   'field_act_year[und][0][value]':{
                            digits:'Please Enter only Year',          
                            minlength:'Please Enter valid year',
                            maxlength:'Please Enter valid year',
                            year_not_greater : 'Year should not be greater than current year',
                                       
                            },
							
						   'field_act_extent[und][0][value]':{
							required: 'Please Enter Act Extent',
							maxlength:  'Maximum 255 character only allowed',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',	
							splchar:'Special Characters are not allowed',
							},
							
						   'field_act_comm_date[und][0][value][date]':{
                            required: 'Please Choose Commencement Date',
                            dateformat: 'Invalid Date format',
                            date_notgreater_tdy: 'Commencement Date should not be greater than today date.',
                                                       
                            },
							
						   'field_act_objectives[und][0][value]':{
							required: 'Please Enter Act Objectives',
							maxlength:  'Maximum 255 character only allowed',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',
							splchar:'Special Characters are not allowed',	
							
							},
							
							'title': { 
							required:  'Please enter Title',
							minlength: 'Minimum 5 characters should be entered',
							maxlength: 'Maximum 255 character only allowed',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',
							splchar:'Special Characters are not allowed',
							},
							
					
						   'field_act_details[und]': { 
							required: 'Please select Acts available option',
							maxlength:  'Invalid option',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',
							},
							
							'field_act_url[und][0][value]':{
							 required: "Please Enter URL",
							 url: 'Not Valid URL',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',

							},
							
							'files[field_act_file_upload_und_0]':{
							required: 'Please select upload file',
							chkfile_format_size: 'Invalid File Format',
							},
							
							'field_act_keyword[und][0][value]':{
							minlength: 'Minimum 5 characters should be entered',
							maxlength:  'Maximum 255 character only allowed',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',	

							splchar:'Special Characters are not allowed',				
							},
	
				}, 
					//errorLabelContainer: "#errormsg_container",
					 //focusInvalid: false,
   					invalidHandler: function(form, validator) {
       
       					 if (!validator.numberOfInvalids())
								return;
						else{
							
							  //$("#actform-node-form").create_errormsg_container('errormsg_container','actform-node-form');
						}
							
							$('html, body').animate({
								scrollTop: $(validator.errorList[0].element).offset().top - 100
							}, 1000);
							
						},
				

   
	});
 /*errorLabelContainer: "#announcements-node-form",
						wrapper: "li",
  
	});
/*  errorPlacement: function(error, element) {
        element = element.closest('li');
        element = element.children(':first-child');
        error.insertBefore(element);
        error.addClass('message');
        $(function() {                                 // my function
            var errorIndex = $(error).index('div');
            var errorId = 'errordiv' + errorIndex.toString();
            $(error).attr('id', errorId);
            $('.errorList').append('<li><a href="#' + errorId + '">' + $(error).text() + '</a></li>');
			$("#announcements-node-form").before(element);
        });    
    },
*/

//// Title Validation
//    $('#edit-title').rules("add", { 
//    		//notaccept: {'exp':"[a-zA-Z]+"},
//			chkbadchar: true,
//    		//required: true,
//         	minlength: 0,
//         messages: {
//            // required: "Title is required"  ,
//           // notaccept: 'Number is Not Allowed',
//			chkbadchar:'blah blah'
//         }
//        
//     });

            
});
